using System;
using System.Collections.Generic;
using Oracle.ManagedDataAccess.Client;

namespace OracleInternal.Sharding
{
	internal class ListShardingKeys : ShardingKeys
	{
		private List<Tuple<OracleShardingKeyImpl, OracleShardingKeyImpl>> m_keys;

		internal override List<Tuple<OracleShardingKeyImpl, OracleShardingKeyImpl>> Keys
		{
			get
			{
				return m_keys;
			}
			set
			{
				m_keys = value;
			}
		}

		internal ListShardingKeys(List<OracleShardingKeyImpl> keys)
		{
			if (keys != null)
			{
				m_keys = new List<Tuple<OracleShardingKeyImpl, OracleShardingKeyImpl>>(keys.Count);
				foreach (OracleShardingKeyImpl key in keys)
				{
					m_keys.Add(new Tuple<OracleShardingKeyImpl, OracleShardingKeyImpl>(key, key));
				}
			}
			else
			{
				m_keys = new List<Tuple<OracleShardingKeyImpl, OracleShardingKeyImpl>>();
			}
		}

		internal override bool Contains(OracleShardingKeyImpl key)
		{
			return m_keys.Contains(new Tuple<OracleShardingKeyImpl, OracleShardingKeyImpl>(key, key));
		}

		public override int GetHashCode()
		{
			if (Keys == null)
			{
				throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.SHARDING_INVALID_TOPOLOGY));
			}
			int num = 0;
			for (int i = 0; i < Keys.Count; i++)
			{
				num += Keys[i].Item1.GetHashCode();
			}
			return num;
		}

		public override bool Equals(object obj)
		{
			ListShardingKeys listShardingKeys = obj as ListShardingKeys;
			if (listShardingKeys == null)
			{
				return false;
			}
			if (Keys == null || listShardingKeys.Keys == null)
			{
				throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.SHARDING_INVALID_TOPOLOGY));
			}
			if (Keys.Count != listShardingKeys.Keys.Count)
			{
				return false;
			}
			for (int i = 0; i < Keys.Count; i++)
			{
				if (!Keys[i].Equals(listShardingKeys.Keys[i]))
				{
					return false;
				}
			}
			return true;
		}
	}
}
